/*
 * @(#)InitialServlet.java   
 *
 * Project: CUPSecureBM
 * 
 * Modify Information:
 *  Author          Date                Description
 * ==============   =================   =====================
 *  yonggangguo     2005-12-29             Create this file
 *
 * Copyright notice:
 *   Copyright (c) 2001-2005 Beijing HiTRUST Technology Co., Ltd.
 *   1808 Room, Science & Technology Building, No. 9 South Street,
 *   Zhong Guan Cun, Haidian District, Beijing ,100081, China
 *   All rights reserved.
 *
 *   This software is the confidential and proprietary information of
 *   HiTRUST.COM, Inc. ('Confidential Information').  You shall not
 *   disclose such Confidential Information and shall use it only in
 *   accordance with the terms of the license agreement you entered
 *   into with HiTRUST.
 */

package com.hitrust.gs.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Properties;
import java.util.Timer;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.PropertyConfigurator;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.hssf.util.Region;

import javax.servlet.http.HttpServletRequest;

import com.hitrust.gs.business.GSManufactureProcessor;
import com.hitrust.gs.dao.GSOrganizationDAO;
import com.hitrust.gs.integration.GSApepInfoProcess;
import com.hitrust.gs.integration.GSServerListener;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.lib.GSLogWriter;
import com.hitrust.gs.lib.GSSystemConfigurator;
import com.hitrust.gs.lib.db.DBConnectionManager;
import com.hitrust.gs.lib.db.backup.DataTask;
import com.hitrust.gs.net.GSAuditFlowManager;
import com.hitrust.gs.util.date.DateUtil;
import com.hitrust.gs.util.exception.GSException;
import com.hitrust.gs.util.lang.StringUtils;
import com.hitrust.gs.util.menu.BuildTreeMenu;
import com.hitrust.gs.util.security.Base64;


public class GSShowBulletinServlet extends HttpServlet {
	
	public static String FILENAME="data.xls";
	
    public void init(ServletConfig aConfig) throws ServletException {
        super.init(aConfig);
    }


    public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException {
    	response.setContentType( "application/excel;charset=UTF-16");
    	response.setHeader("Content-disposition","attachment; filename=data.xls" );
    	


    	
		String tOutputFile=GSSystemConfigurator.getParam("gs.auth.savepath")+"/"+FILENAME;
		String tOutputPath=GSSystemConfigurator.getParam("gs.auth.savepath");
	    try{
			File tFile = new File(tOutputFile);
	        FileInputStream tInputStream = new FileInputStream(tFile);
	        OutputStream tOutputStream = response.getOutputStream();
	        byte[] buff = new byte[1024];
	        int readCount = 0;
	        readCount = tInputStream.read(buff);
	        while (readCount != -1){
	            tOutputStream.write(buff, 0, readCount); 
	           readCount = tInputStream.read(buff);
	        }
	        tOutputStream.flush();
	        if (tInputStream!=null){
	            tInputStream.close();
	        }
	        if (tOutputStream!=null){
	            tOutputStream.close();
	        }
	    }catch(IOException ex){
	    	ex.printStackTrace();
	    }     
    }
    public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException {
    	doPost(request,response);
    }

	
	public static void main(String[] args){
		try{	
			HSSFWorkbook tWb = new HSSFWorkbook();
	    	HSSFSheet tSheet = tWb.createSheet();
	    	tWb.setSheetName(0,"采购分析月报表",HSSFCell.ENCODING_UTF_16);
	    	HSSFRow tRow = tSheet.createRow((short)0);
	    	//起始行,起始列,结束行,结束列,起始和结束相同,表示只有1列
	    	Region region = new Region(5, (short)0, 4, (short)1);

	    	tSheet.addMergedRegion(region);
	    	HSSFRow row = tSheet.createRow((short)8);
	    	HSSFCell cell = row.createCell((short)3);
	    	cell.setCellValue("aaaa");
	    	
	    	File tFile = new File("c:/a.xls");
	    	FileOutputStream fileOut = new FileOutputStream(tFile);
	    	tWb.write(fileOut);
	    	fileOut.flush();
	    	fileOut.close();
		}catch(Exception e){
		    e.printStackTrace();
		}
	}
}
